<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="net.tanesha.recaptcha.ReCaptcha" %>
<%@ page import="net.tanesha.recaptcha.ReCaptchaFactory" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>ReCaptcha</title>
<script>
var RecaptchaOptions = {
   theme: 'blackglass',
   tabindex: 2
};

var obj=false;

function procesar()
{

    if(window.XMLHttpRequest)
    {
    	obj=new XMLHttpRequest();
    }
    else
    {
		return false;
    }
    obj.onreadystatechange=function()
    	{
        	if(obj.readyState==4&&(obj.status==200||window.location.href.indexOf("http")==-1))
        	{
            	//document.getElementById("RptaInner").innerHTML=obj.responseText;
            	if(obj.responseText=="FAIL")
            	{
	            	alert('Ha introducido un captcha incorrecto, intente de nuevo ...');
	            	document.getElementById("rpta").value="FAIL";
	            	document.location.reload(true);
            	}
            	else
           		{
           			document.getElementById("rpta").value="OK";
           			parent.document.formNuevoComprador.submit();
           		}
        	}
        	//else{//procesando...}
		};
	var params="recaptcha_challenge_field="+Recaptcha.get_challenge()+"&recaptcha_response_field="+Recaptcha.get_response();
	obj.open("POST","ServletCaptcha",true);
	obj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    obj.send(params);

   //return (true);
}
</script>

</head>
<body>
<div align="center">
<!--form id="formCaptcha" name="formCaptcha" action="captcha.jsp" method="post"-->
<form id="formCaptcha" name="formCaptcha" action="javascript:procesar();" method="post">
<%
	ReCaptcha c=ReCaptchaFactory.newReCaptcha("6LehxdMSAAAAADP1g6M7Hku-XjsI1Y-cmy6rhNzR","6LehxdMSAAAAABO1oYVTno5kB0yBkm7thx8QTOBq",false);
	out.print(c.createRecaptchaHtml(null,null));
%>
</form>
<input id="rpta" type="hidden" name="rpta" value="FAIL">
<!-- div id="RptaInner"></div-->
</body>
</html>